layui.config({
    base: $config.resUrl+'other/'//定义基目录
}).extend({
    ajaxExtention:'js/ajaxExtention',//加载自定义扩展，每个业务js都需要加载这个ajax扩展
    $tool:'js/tool',
    $api:'js/api'
}).use(['form','layer','laydate','ajaxExtention','$tool','$api'], function() {
	var $ = layui.jquery, 
	laydate = layui.laydate,
	dtree = layui.dtree,
	form = layui.form,
	layer = layui.layer,
	$tool = layui.$tool,
    $api = layui.$api;
	
	//日期
	laydate.render({
    elem: '#operateTime'
	});
	
	//监听提交按钮
	form.on('submit(userEditSubmit)', function(data){
	  
	  var roles = [];
	  $("input[name='roles']:checked").each(function() {
		  roles.push($(this).val());
      });
	  var seq = data.field;
	  //获取选中的角色
	  seq.roles = roles;
	  
	  $api.UserUpdate(seq,function(data){
		  layer.msg(data.msg,{time: 2000},function(){
			  parent.layer.closeAll();
		  });
	  },function(error){
		  layer.msg(error.msg);
	  });
	  form.render();
  });
  
  //机构弹出框
  $("[name=deptName]").click(function(){
	  layer.open({
	    type: 1,
	    title: "部门列表",
	    area: ["350px", "80%"],
	    content: '<ul id="deptTree" class="dtree" data-id="0"></ul>',
	    btn: ['确认选择'],
	    success: function(layero, index){
	      dtree.render({
	      //  obj: $(layero).find("#openTree1"),    如果直接用elem加载不出来，则可以使用这个方式加载jquery的DOM
	        elem: "#deptTree",
	        url: "/sys/dept/tree.json",
	        dot: false
	      });
	      // 绑定节点的双击
	      dtree.on("nodedblclick('deptTree')", function(obj){
	        $("#deptId").val(obj.param.nodeId);
	        $("#deptName").val(obj.param.context);
	        layer.close(index);
	      });
	    },
	    yes: function(index, layero) {
	      var param = dtree.getNowParam("deptTree"); // 获取当前选中节点
	      $("#deptId").val(param.nodeId);
	      $("#deptName").val(param.context);
	      layer.close(index);
	    }
	  });
	});
});
